package cn.lili.controller.promotion;

import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.promotion.entity.dos.GreenProject;
import cn.lili.modules.promotion.service.GreenProjectService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@Api(tags = "绿色公益项目接口")
@RequestMapping("/promotion/gc/project")
@RequiredArgsConstructor
public class GreenProjectController {

    private final GreenProjectService greenProjectService;

    @GetMapping("/getPageByAll")
    @ApiModelProperty("分页获取公益项目")
    public ResultMessage<Object> getByPage (PageVO pageVO) {
        return ResultUtil.data(greenProjectService.getPageByAll(pageVO));
    }

    @GetMapping("/getBalance")
    @ApiModelProperty("获取公益项目账户余额")
    public ResultMessage<Object> getBalance () {
        return ResultUtil.data(greenProjectService.getBalance());
    }

    @GetMapping("/getByLast")
    @ApiModelProperty("获取最新一个公益项目")
    public ResultMessage<GreenProject> getByLast () {
        GreenProject greenProject = greenProjectService.getByLast();
        return ResultUtil.data(greenProject);
    }

    @GetMapping("/getByPage")
    @ApiModelProperty("分页获取公益项目")
    public ResultMessage<Page<GreenProject>> getByPage (GreenProject greenProject, PageVO pageVO) {
        return ResultUtil.data(greenProjectService.getByPage(greenProject, pageVO));
    }

    @GetMapping("/getById")
    @ApiModelProperty("根据ID获取公益项目详情")
    public ResultMessage<GreenProject> getById (String id) {
        return ResultUtil.data(greenProjectService.getById(id));
    }

    @PostMapping("/edit")
    @ApiModelProperty("编辑公益项目")
    public ResultMessage<Object> edit (@RequestBody GreenProject greenProject) {
        greenProjectService.editProject(greenProject);
        return ResultUtil.success();
    }

    @PostMapping("/add")
    @ApiModelProperty("添加公益项目")
    public ResultMessage<Object> add (@RequestBody GreenProject greenProject) {
        greenProjectService.addProject(greenProject);
        return ResultUtil.success();
    }
}
